package com.taotao.rest.service.impl;

import java.util.ArrayList;
import java.util.List;

import org.springframework.stereotype.Service;

import com.taotao.common.pojo.EasyUITree;
import com.taotao.mapper.TbContentCategoryMapper;
import com.taotao.pojo.TbContentCategory;
import com.taotao.pojo.TbContentCategoryExample;
import com.taotao.pojo.TbContentCategoryExample.Criteria;
import com.taotao.rest.service.ContentCategoryService;


@Service
public class ContentCategoryServiceImpl implements ContentCategoryService{
	
	private TbContentCategoryMapper categoryMapper;

	@Override
	public List<EasyUITree> getContentCategoryList(long parentId) {
		// TODO Auto-generated method stub
		
		TbContentCategoryExample example =new TbContentCategoryExample();
		Criteria criteria=example.createCriteria();
		criteria.andParentIdEqualTo(parentId);
		List<TbContentCategory> list = categoryMapper.selectByExample(example);
		
		List<EasyUITree> resultList=new ArrayList<>();
		for (TbContentCategory tbContentCategory : list) {
			EasyUITree node=new EasyUITree();
			node.setId(tbContentCategory.getId());
			node.setText(tbContentCategory.getName());
			node.setState(tbContentCategory.getIsParent()?"closed":"open");
			resultList.add(node);
		}
		return resultList;
	}

}
